home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / freespy / frmmain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-01-02  |  6.1 KB  |  128 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "FreeSpy by WorldMaker@aol.com"
  4.    ClientHeight    =   2430
  5.    ClientLeft      =   1530
  6.    ClientTop       =   2955
  7.    ClientWidth     =   5835
  8.    Height          =   2835
  9.    Icon            =   FRMMAIN.FRX:0000
  10.    Left            =   1470
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   2430
  13.    ScaleWidth      =   5835
  14.    Top             =   2610
  15.    Width           =   5955
  16.    Begin Timer Timer1 
  17.       Interval        =   100
  18.       Left            =   180
  19.       Top             =   135
  20.    End
  21.    'FreeSpy by WorldMaker@aol.com
  22.    'IvanSkii and I discussed some Visual Basic stuff one day and
  23.    'talk got around to the IVY Spy program he uploaded to AOL a couple
  24.    'of years ago. He said the code was from the Microsoft Visual Basic
  25.    'Knowledge Base. So, I checked. I played. And I added a little to it.
  26.    'I like my VB apps to start up in the center of the screen. In the
  27.    'Form_Load event, you'll find the code which handles this. Also,
  28.    'since I use this little thing to double-check handle values, I find
  29.    'it useful that it stay on top *always*, and when maximized from a
  30.    'minimized state, that it *stay* on top. You'll find the code for that
  31.    'here in the general declarations section.
  32.    'Feel free to do whatever you'd like with this. The code is from the
  33.    'VBKB with minor additions and changes by me. Just have fun. :)
  34.    Declare Sub GetCursorPos Lib "User" (lpPoint As Long)
  35.    Declare Function WindowFromPoint Lib "User" (ByVal ptScreen As Any) As Integer
  36.    Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String, ByVal nSize As Integer) As Integer
  37.    Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
  38.    Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
  39.    Declare Function GetParent Lib "User" (ByVal hWnd As Integer) As Integer
  40.    Declare Function GetClassName Lib "User" (ByVal hWnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
  41.    Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer
  42.    Declare Function SetWindowPos Lib "user" (ByVal h%, ByVal hb%, ByVal X%, ByVal Y%, ByVal cx%, ByVal cy%, ByVal f%) As Integer
  43.    Declare Function GetActiveWindow% Lib "User" ()
  44.    Const GWW_HINSTANCE = (-6)
  45.    Const GWW_ID = (-12)
  46.    Const GWL_STYLE = (-16)
  47.    Const HWND_TOPMOST = -1
  48.    Const HWND_NOTOPMOST = -2
  49.    Const SWP_NOMOVE = 2
  50.    Const SWP_NOSIZE = 1
  51.    Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
  52.    Const SW_MINIMIZE = 6
  53. Sub Form_Load ()
  54.     'This centers the form. I usually add a function to center
  55.     'a form but since this is just a one-form kinda program,
  56.     'I just put it here.
  57.     Me.Left = (screen.Width - Me.Width) / 2
  58.     Me.Top = (screen.Height - Me.Height) / 2
  59.     'This calls the StayOnTop function. You can find this
  60.     'particular function under every rock and in just about
  61.     'every book on Visual Basic. :)
  62.     StayOnTop Me
  63. End Sub
  64. Sub Label1_Click ()
  65. End Sub
  66. Sub StayOnTop (frm As Form)
  67.     Dim success%
  68.     success% = SetWindowPos(frm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
  69. End Sub
  70. Sub Timer1_Timer ()
  71. 'Among the things I played with was removing the Hex function from
  72. 'this code. Personally, I don't care much about Hex values. If that
  73. 'kind of thing floats *your* boat, pull out the KB article and
  74. 'change it back. :)
  75. Dim ptCursor As Long
  76.       Dim sWindowText As String * 100
  77.       Dim sClassName As String * 100
  78.       Dim hWndOver As Integer
  79.       Dim hWndParent As Integer
  80.       Dim sParentClassName As String * 100
  81.       Dim wID As Integer
  82.       Dim lWindowStyle As Long
  83.       Dim hInstance As Integer
  84.       Dim sParentWindowText As String * 100
  85.       Dim sModuleFileName As String * 100
  86.       Static hWndLast As Integer
  87.       Call GetCursorPos(ptCursor)               ' Get cursor position
  88.       hWndOver = WindowFromPoint(ptCursor)      ' Get window cursor is over
  89.       If hWndOver <> hWndLast Then              ' If changed update display
  90.          hWndLast = hWndOver                    ' Save change
  91.          Cls                                      ' Clear the form
  92.          Print "Window Handle: "; (hWndOver) ' Display window handle
  93.          Print "Focus: "; GetActiveWindow()  'I added this
  94.          r = GetWindowText(hWndOver, sWindowText, 100)      ' Window text
  95.          Print "Window Text: " & Left(sWindowText, r)
  96.          r = GetClassName(hWndOver, sClassName, 100)         ' Window Class
  97.          Print "Window Class Name: "; Left(sClassName, r)
  98.          lWindowStyle = GetWindowLong(hWndOver, GWL_STYLE)   ' Window Style
  99.          Print "Window Style: "; (lWindowStyle)
  100.          ' Get handle of parent window:
  101.          hWndParent = GetParent(hWndOver)
  102.          ' If there is a parent get more info:
  103.          If hWndParent <> 0 Then
  104.             ' Get ID of window:
  105.             wID = GetWindowWord(hWndOver, GWW_ID)
  106.             Print "Window ID Number: "; (wID)
  107.             Print "Parent Window Handle: "; (hWndParent)
  108.             ' Get the text of the Parent window:
  109.             r = GetWindowText(hWndParent, sParentWindowText, 100)
  110.             Print "Parent Window Text: " & Left(sParentWindowText, r)
  111.             ' Get the class name of the parent window:
  112.             r = GetClassName(hWndParent, sParentClassName, 100)
  113.             Print "Parent Window Class Name: "; Left(sParentClassName, r)
  114.          Else
  115.             ' Update fields when no parent:
  116.             Print "Window ID Number: N/A"
  117.             Print "Parent Window Handle: N/A"
  118.             Print "Parent Window Text : N/A"
  119.             Print "Parent Window Class Name: N/A"
  120.          End If
  121.          ' Get window instance:
  122.          hInstance = GetWindowWord(hWndOver, GWW_HINSTANCE)
  123.          ' Get module file name:
  124.          r = GetModuleFileName(hInstance, sModuleFileName, 100)
  125.          Print "Module: "; Left(sModuleFileName, r)
  126.       End If
  127. End Sub
  128.